package com.example.model;

/**
 * @author long
 * @date 2023/10/13 15:46
 */
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;
public class StuFactory {

    static Map<String,Stu> stuMap = new HashMap<>();

    static{
        //初始化
        Stream.iterate(1,n->n+1).limit(5).map(String::valueOf).forEach(t-> stuMap.put(t, new Stu(t)));
    }

    //静态创建类，方法必须是静态(static修饰)
    public static Stu getStaticStu(String stuId){
        return stuMap.get(stuId);
    }

    //动态创建类
    public Stu getDynamicStu(String stuId){
        return new Stu(stuId);
    }
}

